package controller

import (
	"token-centre/global"
	"token-centre/model"

	"github.com/gin-gonic/gin"
)

func AppAdd(c *gin.Context) {

	var one model.App

	if err := c.BindJSON(&one); err != nil {
		RtnErr(c, "参数解析失败", err)
		return
	}

	if err := global.Db.Create(&one).Error; err != nil {
		RtnErr(c, "创建失败！", err)
		return
	}

	Rtn(c, "成功", nil)
}

func AppList(c *gin.Context) {

	// var params = struct {
	// 	Page  int
	// 	Limit int
	// }{1, 10}

	// c.BindJSON(&params)

	var list []model.App

	if err := global.Db.Find(&list).Error; err != nil {
		RtnErr(c, "创建失败！", err)
		return
	}

	Rtn(c, "成功", list)
}

func AppDelete(c *gin.Context) {
	var id = c.GetUint("id")
	var one model.App
	one.ID = id

	if err := global.Db.Delete(&one).Error; err != nil {
		RtnErr(c, "创建失败！", err)
		return
	}

	Rtn(c, "成功", nil)
}
